//
//  AVPlayerTableViewCell.m
//  ReviewDemo
//
//  Created by 龙 on 2018/5/10.
//  Copyright © 2018年 long. All rights reserved.
//

#import "AVPlayerTableViewCell.h"
#import <Masonry.h>

@implementation AVPlayerTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setAVPlayerTableViewCellUI:self.contentView];
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setAVPlayerTableViewCellUI:(UIView *)superView
{
    [superView addSubview:self.adressLable];
    [superView addSubview:self.videoView];
    [superView addSubview:self.playButton];

    [self.adressLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(20);
    }];
    [self.videoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.adressLable.mas_bottom).with.offset(10);
        make.left.bottom.mas_equalTo(10);
        make.right.mas_equalTo(-10);
    }];
    
    [self.playButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(superView);
    }];
}

- (void)playButtonDidClick
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(cellPlayButtonDidClick:)]) {
        [self.delegate cellPlayButtonDidClick:self];
    }
}


#pragma mark - setter and getter

- (UILabel *)adressLable
{
    if (_adressLable == nil)
    {
        UILabel *lable = [[UILabel alloc] init];
        lable.backgroundColor = [UIColor clearColor];
        lable.textAlignment = NSTextAlignmentCenter;
        _adressLable = lable;
    }
    return _adressLable;
}

- (UIView *)videoView
{
    if (_videoView == nil)
    {
        UIView *view = [[UIView alloc] init];
        
        _videoView = view;
    }
    return _videoView;
}

- (UIButton *)playButton
{
    if (_playButton == nil)
    {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(playButtonDidClick) forControlEvents:UIControlEventTouchUpInside];
        [button setImage:[UIImage imageNamed:@"playVideo"] forState:UIControlStateNormal];
        
        _playButton = button;
    }
    return _playButton;
}

@end
